package cc.web.vaaking.services;

import cc.web.vaaking.common.DB.SuperSessionFactory;
import cc.web.vaaking.entity.SysRole;
import cc.web.vaaking.mapper.MiscMapper;
import cc.web.vaaking.mapper.SysRoleMapper;
import cc.web.vaaking.mapper.SysUserMapper;
import org.apache.ibatis.session.SqlSession;

public class SysRoleService {
    public SysRole selectSysRoleByUserId(int userId) {
        try (SqlSession session = SuperSessionFactory.sqlSessionFactory.openSession()) {
            SysRoleMapper sysRoleMapper = session.getMapper(SysRoleMapper.class);
            SysRole sysRole = sysRoleMapper.getRoleByUserId(userId);
            return sysRole;
        }
    }

    public int updateUserRoleByUserId(int userId, int roleId) {
        try (SqlSession session = SuperSessionFactory.sqlSessionFactory.openSession(true)) {
            SysRoleMapper sysRoleMapper = session.getMapper(SysRoleMapper.class);
            return sysRoleMapper.updateUserRoleByUserId(userId, roleId);
        }
    }
}
